package structurepattern.filter;

import java.util.List;

/**
 * filter Person list which meet criteria or otherCriteria
 */
public class OrCriteria implements Criteria {
	protected Criteria criteria;
	protected Criteria otherCriteria;
	
	public OrCriteria(Criteria criteria, Criteria otherCriteria) {
		this.criteria = criteria;
		this.otherCriteria = otherCriteria;
	}
	
	@Override
	public List<Person> meetCriteria(List<Person> persons) {
		List<Person> firstCriteriaPersons = criteria.meetCriteria(persons);
		List<Person> otherCriterialPersons = criteria.meetCriteria(persons);
		
		for(Person person: otherCriterialPersons)
		{
			if(!firstCriteriaPersons.contains(person))
			{
				firstCriteriaPersons.add(person);
			}
		}
		
		return firstCriteriaPersons;
	}
}
